
import { SipLoggerSend, SipLoggerRecv, SipMessage, SipRemote, SipCallback, SipServiceOptions } from "./Common";
import { SipUDPTransport } from "./sipUdpTransPort";

export interface SipTransportProtocols {
    UDP?: SipUDPTransport;//TODO
    TCP?: any;//TODO
    TLS?: any;//TODO
    WS?: any;//TODO
}

export class SipTransport {
    private sendLog: SipLoggerSend = (message: SipMessage, target: any) => { };
    private recvLog: SipLoggerRecv = (message: SipMessage, remote: SipRemote) => { };
    private protocols: SipTransportProtocols = {};
    constructor(options: SipServiceOptions, callback: SipCallback) {
        let callbackAndLog: SipCallback = callback;
        if (options.logger && options.logger.recv) {
            callbackAndLog = (message: SipMessage, remote: SipRemote, stream?: Buffer) => {
                console.log("SipTransport with recvLog[onData]");
                this.recvLog(message, remote);
                console.log("SipTransport with recvLog[callback]");
                callback(message, remote, stream);
            };
        }
        this.protocols.UDP = new SipUDPTransport(options,callbackAndLog);
    }
}